<?php
class ZonasController extends AppController {

	var $name = 'Zonas';
	var $components = array('RequestHandler');
	
	function index(){
		$this->layout="ajax";		
		
		if($this->JQGridPaginate->isGrid){
			$fields = array('Zona.id','Zona.codigo','Zona.descripcion','"Zona"."created"::date AS "Zona__created"','"Estado"."descripcion" AS "Zona__estado"');
			$this->JQGridPaginate->recursive = 0;
			$this->JQGridPaginate->cakefields = $fields;
			echo $this->JQGridPaginate->paginate("Zona");
			$this->autoRender = false;
		}elseif($this->RequestHandler->isPost()){	
			$oper = $this->params['form']['oper'];
			if($oper == "add"){
				$this->Zona->create();				 
			}elseif ($oper == "edit"){
				$this->data['Zona']['id'] = $this->params['form']['id'];
			}elseif ($oper == "del"){
				$this->data['Zona']['id'] = $this->params['form']['id'];
				$this->data['Zona']['estado_id'] = 2;				
			}
			
			@$this->Zona->save($this->data['Zona']);
			echo json_encode($this->Zona->visualizarError($this->Zona->validationErrors));
			$this->autoRender = false;			
		}		
	}	
}